#ifndef COMMONUTIL_H
#define COMMONUTIL_H

/**
 * @file commonutil.h
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2023-11-21
 *
 * @copyright Copyright (c) 2023
 *
 */

// #include "CommonUtils_global.h"
#include <QDebug>
#include <QTime>
#include <QtMath>
#include <QtCore/qmath.h>
#include <QPointF>

// class QColor;

namespace ns_yht
{
    class /*COMMONUTILS_EXPORT*/ CommonUtil
    {

    public:
        explicit CommonUtil();
        ~CommonUtil();

        static void prtInfo(const QString modeString, const QString varString, const QString valueString);

        static QString getMultiNmea(const QString sentence);

        static qint64 getUtc(const QString timeString, const int typeInt);

        /**
         * @brief getSignedInt将二进制字符串转换为带符号的整数
         * @param valueString 二进制字符串，例如1111 1000
         * @param bitNumberInt 二进制位数，例如8位
         * @return 带符号的整数，例如-8
         */
        static int getSignedInt(const QString valueString, const int bitNumberInt);

        /**
         * @brief 检查Nmea报文有效性
         * @param
         * @return
         */
        static bool checkNmeaValid(const QString sentence);

        /**
         * @brief 去掉左边字符串
         * @param
         * @return
         */
        static QString trimLeft(const QString sentence, const QString markString);

        //        static const QString colorToString(const QColor &color, bool hasAlpha = true);
        //        static const QColor stringToColor(const QString &scolor);

        static QString getWeekString(int dayofweek);

#if 0 // 移到LonLatUtil.h
    /**
     * @brief Get the Lonlat String object 将经纬度数值转换为字符串
     * @param lonlatDouble
     * @param typeInt 0-度，1-度分 2-度分秒
     * @return QString
     */
    static QString getLonlatString(const double lonlatDouble, const int typeInt);

    /**
     * @brief 将字符串转换为经纬度
     * @param
     * @return
     */
    static double getLonlat(const QString lonlatString, const int typeInt);

    static bool isCoorValid(qreal lat, qreal lon);
    static bool isCoorValid(const QPair<double, double> &coor);

    /**
     * @brief 把实数型经纬度(如123.3456344)转换为度分秒格式
     * @param coor  实数经度或纬度坐标
     * @param dnum  保留秒的小数位数
     * @param isLon 是否是经度
     * @param ignoreMinus   忽略正负
     * @return
     */
    static QString convertCoordinateToString(double coor, int dnum = 1, bool isLon = true, bool ignoreMinus = false, const QString &sd = "°", const QString &sm = "′", const QString &ss = "″");
    static double convertCoordinateToDouble(const QString &strcoor);                                                                         // 把度分秒格式经纬度转换为实数型格式
    static void convertCoordinate(double coor, int &degree, int &minute, int &second, int &decimal, int format);                             // format-参考MLonLatEdit
    static QString convertCoordinate(double coor, int dnum, bool isLon, bool ignoreMinus, const QString &sd = "°", const QString &sm = "′"); // 转换为度分格式，分带小数
#endif

        static bool floatEqual(double a, double b, double err = 1e-6);

        static QString getSpeedString(double speed);
        static QString getAngleString(double angle);
        static QString getTcpaString(double tcpa);
        static QString getDistanceString(double distance);

        static double getDcpaFromIndex(int index);
        static double getTcpaFromIndex(int index);
        static int getDutyAlarmTimeFromIndex(int index);
    };

} // namespace ns_yht

#endif // COMMONUTIL_H
